home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Tele / Pete Johnson / mehit 3.0.b15<source>.cpt / Help.p < prev    next >
Text File  |  1991-06-22  |  6KB  |  227 lines

  1. unit Help;
  2.  
  3. interface
  4.  
  5. procedure Help (strRsrcNum, hlpRsrcNum: Integer);
  6.  
  7. implementation
  8.  
  9. type
  10.     TopicSet = record
  11.             textRsrc, stylRsrc: Integer;
  12.         end;
  13.     HelpListHdl = ^HelpListPtr;
  14.     HelpListPtr = ^HelpList;
  15.     HelpList = record
  16.             numTopics: Integer;
  17.             topicSets: array[0..0] of TopicSet;
  18.         end;
  19. var
  20.     myDialog: DialogPtr;
  21.     myHelpListH: HelpListHdl;
  22.     theList: ListHandle;
  23.     pagesize, numTopics: Integer;
  24.     textRes, numTopicsH: Handle;
  25.     sBar: ControlHandle;
  26.     theText: TEHandle;
  27.  
  28. procedure CreateList (strRsrcNum: integer);
  29.     var
  30.         i, iType: Integer;
  31.         topicStr: Str255;
  32.         iRect, dataBounds: Rect;
  33.         cSize, theCell: Cell;
  34.         iHandle: Handle;
  35.     begin
  36.         GetDItem(myDialog, 3, iType, iHandle, iRect);
  37.         FrameRect(iRect);
  38.         InsetRect(iRect, 1, 1);
  39.         SetPt(cSize, iRect.right - iRect.left, 17);
  40.         SetRect(dataBounds, 0, 0, 1, numTopics);
  41.         theList := LNew(iRect, dataBounds, cSize, 0, myDialog, False, False, False, True);
  42.         for i := 1 to numTopics do                    {drawIt, hasGrow, hScroll, vScroll}
  43.             begin
  44.                 GetIndString(topicStr, strRsrcNum, i);
  45.                 SetPt(theCell, 0, i - 1);
  46.                 LSetCell(Pointer(Ord(@topicStr) + 1), Length(topicStr), theCell, theList);
  47.             end;
  48.         theList^^.selFlags := lOnlyOne;
  49.         SetPt(theCell, 0, 0);
  50.         LSetSelect(true, theCell, theList);
  51.         LDoDraw(True, theList); {set drawing to True now that list is built}
  52.     end;
  53.  
  54. procedure ScrAction (theCtl: ControlHandle; partCode: Integer);
  55.     var
  56.         delta, oldValue: Integer;
  57.     begin
  58.         case partCode of
  59.             inUpButton: 
  60.                 delta := -10;
  61.             inDownButton: 
  62.                 delta := 10;
  63.             inPageUp: 
  64.                 delta := -pagesize;
  65.             inPageDown: 
  66.                 delta := pagesize;
  67.             otherwise
  68.         end;
  69.         if partCode <> 0 then
  70.             begin
  71.                 oldValue := GetCtlValue(theCtl);
  72.                 SetCtlValue(theCtl, oldValue + delta);
  73.                 TEScroll(0, oldValue - GetCtlValue(theCtl), theText);
  74.             end;
  75.     end;
  76.  
  77. procedure WindowScroll (thePt: Point; theWindow: WindowPtr);
  78.     var
  79.         theCtl: ControlHandle;
  80.         part, oldValue: Integer;
  81.     begin
  82.         GlobalToLocal(thePt);
  83.         case FindControl(thePt, theWindow, theCtl) of
  84.             inUpButton..inPageDown: 
  85.                 part := TrackControl(theCtl, thePt, @ScrAction);
  86.             inThumb: 
  87.                 begin
  88.                     with theText^^ do
  89.                         oldValue := viewRect.top - destRect.top;
  90.                     if TrackControl(theCtl, thePt, nil) <> 0 then
  91.                         TEScroll(0, oldValue - GetCtlValue(theCtl), theText);
  92.                 end;
  93.             otherwise
  94.         end;
  95.     end;
  96.  
  97. procedure LoadText (item: Integer);
  98.  
  99.     const
  100.         inactive = 255;
  101.  
  102.     var
  103.         max, textNum, stylNum: Integer;
  104.         textRes, stylRes: Handle;
  105.  
  106.     begin
  107.         TEDeactivate(theText);
  108.         TESetSelect(0, 32767, theText);
  109.         TEDelete(theText);
  110.         theText^^.destRect := theText^^.viewRect;
  111.         textNum := myHelpListH^^.topicSets[item].textRsrc;
  112.         stylNum := myHelpListH^^.topicSets[item].stylRsrc;
  113.         if (textNum <> 0) & (stylNum <> 0) then
  114.             begin
  115.                 textRes := GetResource('TEXT', textNum);
  116.                 stylRes := GetResource('styl', stylNum);
  117.                 HLock(textRes);
  118.                 HLock(stylRes);
  119.                 TEStylInsert(textRes^, SizeResource(textRes), StScrpHandle(stylRes), theText);
  120.                 HUnlock(stylRes);
  121.                 HUnlock(textRes);
  122.             end;
  123.         max := TEGetHeight(theText^^.nLines, 0, theText) - pagesize;
  124.         if max > 0 then
  125.             HiliteControl(sBar, activeFlag)
  126.         else
  127.             HiliteControl(sBar, inactive);
  128.         SetCtlValue(sBar, 0);
  129.         SetCtlMax(sBar, max);
  130.         TEActivate(theText);
  131.     end;
  132.  
  133. function MyFilter (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: Integer): Boolean;
  134.     var
  135.         iType, part: Integer;
  136.         iBox: Rect;
  137.         iHdl: Handle;
  138.         thePt: Point;
  139.         theCtl: ControlHandle;
  140.         ignore: Boolean;
  141.         newCell: Cell;
  142.     begin
  143.         MyFilter := False;
  144.         case theEvent.what of
  145.             keyDown, autoKey:  {close if enter or return is keyed}
  146.                 if BitAnd(theEvent.message, charCodeMask) in [3, 13] then
  147.                     begin
  148.                         MyFilter := True;
  149.                         GetDItem(theDialog, 1, iType, iHdl, iBox);
  150.                         InvertRoundRect(iBox, 10, 10);
  151.                         itemHit := 1;
  152.                     end;
  153.             mouseDown: 
  154.                 begin
  155.                     thePt := theEvent.where;
  156.                     GlobalToLocal(thePt);
  157.                     part := FindControl(thePt, myDialog, theCtl);
  158.                     if theCtl = sBar then
  159.                         WindowScroll(theEvent.where, myDialog)
  160.                     else if theCtl = theList^^.vScroll then
  161.                         ignore := LClick(thePt, theEvent.modifiers, theList)
  162.                     else if PtInRect(thePt, theList^^.rView) then
  163.                         begin
  164.                             ignore := LClick(thePt, theEvent.modifiers, theList);
  165.                             SetPt(newCell, 0, 0);
  166.                             ignore := LGetSelect(True, newCell, theList);
  167.                             LoadText(newCell.v);
  168.                         end;
  169.                 end;
  170.             updateEvt: 
  171.                 begin
  172.                     TEUpdate(theText^^.viewRect, theText);
  173.                     LUpdate(myDialog^.visRgn, theList);
  174.                 end;
  175.             otherwise
  176.         end;
  177.     end;
  178.  
  179. procedure Help;  {(strRsrcNum, hlpRsrcNum: Integer)}
  180.  
  181.     type
  182.         IntHdl = ^IntPtr;
  183.         IntPtr = ^Integer;
  184.  
  185.     var
  186.         savePort: GrafPtr;
  187.         iBox, tBox: Rect;
  188.         iType, itemHit: Integer;
  189.         iHdl: Handle;
  190.  
  191.     begin
  192.         GetPort(savePort);
  193.         myDialog := GetNewDialog(257, nil, Pointer(-1));
  194.         SetPort(myDialog);
  195.         DrawDialog(myDialog);
  196.         TextFont(0);
  197.         TextSize(12);
  198.         numTopics := IntHdl(GetResource('STR#', strRsrcNum))^^;
  199.         myHelpListH := HelpListHdl(GetResource('HLP#', hlpRsrcNum));
  200.         HLock(Handle(myHelpListH));
  201.         CreateList(strRsrcNum);
  202.         GetDItem(myDialog, 2, iType, iHdl, tBox);
  203.         FrameRect(tBox);
  204.         InsetRect(tBox, 4, 2);
  205.         pagesize := tBox.bottom - tBox.top;
  206.         theText := TEStylNew(tBox, tBox);
  207.         HLock(Handle(theText));
  208.         GetDItem(myDialog, 6, iType, iHdl, iBox);
  209.         sBar := ControlHandle(iHdl);
  210.         GetDItem(myDialog, 1, iType, iHdl, iBox);
  211.         InsetRect(iBox, -4, -4);
  212.         PenSize(3, 3);
  213.         FrameRoundRect(iBox, 16, 16);
  214.         PenSize(1, 1);
  215.         LoadText(0);
  216.         repeat
  217.             ModalDialog(@MyFilter, itemHit);
  218.             DrawDialog(myDialog);
  219.         until itemHit = 1;
  220.         HUnlock(Handle(theText));
  221.         LDispose(theList);
  222.         Hunlock(Handle(myHelpListH));
  223.         DisposDialog(myDialog);
  224.         SetPort(savePort);
  225.     end;
  226.  
  227. end.